/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package View.ClusterizationPanel;

import java.awt.Color;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Snowangelic
 */
public class CentroidTableModel extends AbstractTableModel implements TableModelListener {

    ClusterizationWindow main;

    CentroidTableModel(ClusterizationWindow main){
        this.main=main;
    }

    @Override
    public String getColumnName(int col) {
        if(col==0) return "No";
        else if (col==1) return "Name";
        else if (col==2) return "Color";
        else return main.getAttributeName(col-3);
    }

    public int getRowCount() {
        return main.getNumberOfClusters();
    }

    public int getColumnCount() {
        return main.getAttributeNbr()+3;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        if(columnIndex==0)return rowIndex+1;
        else if(columnIndex==1) return main.getClusterName(rowIndex);
        else if(columnIndex==2) return main.getClusterColor(rowIndex);
        else return main.getCentroidValue(rowIndex,columnIndex-3);
    }

    public Class getColumnClass(int columnIndex) {
        if (columnIndex == 2)//Troisieme colonne est celle de la couleur
            return Color.class;
        else
            return java.lang.Object.class;
    }

    public boolean isCellEditable(int row, int col) {
        if (col==1) return true;
        else return false;
    }

    public void setValueAt(Object value, int row, int col) {
        if(col==1) main.setClusterName(row,value.toString());
    }


    public void tableChanged(TableModelEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

}
